/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanPiocheCarte.java
 *
 * Created on 15 janv. 2012, 15:24:12
 */
package InterfaceGraphique.commonPannel;

import InterfaceGraphique.FenJeuEntrer;
import InterfaceGraphique.MainApplication;
import cartes.Carte;
import cartes.Malediction;
import common.Constantes;
import java.awt.Font;
import java.awt.Image;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import plateau.Partie;

    
/**
 *
 * @author Arthur
 */
public class PanPiocheCarte extends javax.swing.JPanel {

    private Carte carte;
    
    /** Creates new form PanPiocheCarte */
    public PanPiocheCarte() {
        this.setBackground(new java.awt.Color(110,48,34));
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        bAjouterMain = new javax.swing.JButton();
        bDefausser = new javax.swing.JButton();
        bSubir = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(820, 600));
        setPreferredSize(new java.awt.Dimension(820, 600));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setForeground(new java.awt.Color(213, 151, 0));
        jLabel1.setText("Le donjon semble inhabité... Mais vous trouvez ");
        jLabel1.setName("jLabel1"); // NOI18N
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(24.0f);
            this.jLabel1.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        bAjouterMain.setText("Prendre");
        bAjouterMain.setName("bAjouterMain"); // NOI18N
        bAjouterMain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bAjouterMainActionPerformed(evt);
            }
        });
        add(bAjouterMain, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 550, 120, 30));

        bDefausser.setText("Laisser");
        bDefausser.setName("bDefausser"); // NOI18N
        bDefausser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bDefausserActionPerformed(evt);
            }
        });
        add(bDefausser, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 550, 110, 30));

        bSubir.setText("Subir");
        bSubir.setName("bSubir"); // NOI18N
        bSubir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSubirActionPerformed(evt);
            }
        });
        add(bSubir, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 550, 90, 30));
        this.bSubir.setVisible(false);

        jLabel5.setToolTipText("");
        jLabel5.setName("jLabel5"); // NOI18N
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 80, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void bAjouterMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAjouterMainActionPerformed
        // TODO add your handling code here:
        MainApplication.getJoueurEnCours().getMain().add(this.carte);
        ((FenJeuEntrer)MainApplication.getFenetre(Constantes.FEN_JEU_ENTRER)).combatTermine(MainApplication.getJoueurEnCours());
    }//GEN-LAST:event_bAjouterMainActionPerformed

    private void bDefausserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefausserActionPerformed
        // TODO add your handling code here:
        Partie.getDefausse().add(carte);
        ((FenJeuEntrer)MainApplication.getFenetre(Constantes.FEN_JEU_ENTRER)).combatTermine(MainApplication.getJoueurEnCours());
    }//GEN-LAST:event_bDefausserActionPerformed

    private void bSubirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubirActionPerformed
        // TODO add your handling code here:
        ((Malediction) this.carte).getActionCarte().utiliser(MainApplication.getJoueurEnCours());
        Partie.getDefausse().add(carte);
        ((FenJeuEntrer)MainApplication.getFenetre(Constantes.FEN_JEU_ENTRER)).combatTermine(MainApplication.getJoueurEnCours());
    }//GEN-LAST:event_bSubirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bAjouterMain;
    private javax.swing.JButton bDefausser;
    private javax.swing.JButton bSubir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables

    public void load(Carte c) {
        this.carte = c;
        
        ImageIcon imageCarte = new ImageIcon(getClass().getResource(this.carte.getCheminImage()));
        ImageIcon imageRedim = new ImageIcon(imageCarte.getImage().getScaledInstance(280, 440, Image.SCALE_DEFAULT));
        this.jLabel5.setIcon(imageRedim); // 
            
        // Classe ou race
        if( this.carte.getClass().getName().equals(Constantes.C_CLASSE) || this.carte.getClass().getName().equals(Constantes.C_RACE)) {
            this.bSubir.setVisible(false);
            this.bAjouterMain.setVisible(true);
            this.bDefausser.setVisible(true);
            this.jLabel1.setText("Le donjon semble inhabité... Mais vous trouvez ça !");
        }
        else if ( this.carte.getClass().getName().equals(Constantes.C_MALEDICTION)) {
            this.bAjouterMain.setVisible(false);
            this.bDefausser.setVisible(false);
            this.bSubir.setVisible(true);
            this.jLabel1.setText("Un piège se déclenche lors que vous ouvrez la porte !");
        }
    }
}
